package com.hins.demo.model.transfer.valueobject;

import com.hins.component.exception.Assert;
import lombok.Value;

import java.math.BigDecimal;


@Value
public class ExchangeRate {
    BigDecimal rate;
    Currency from;
    Currency to;

    public ExchangeRate(BigDecimal rate, Currency from, Currency to) {
        this.rate = rate;
        this.from = from;
        this.to = to;
    }

    public Money exchange(Money fromMoney) {
        Assert.notNull(fromMoney);
        Assert.isTrue(this.from.equals(fromMoney.getCurrency()));

        BigDecimal targetAmount = fromMoney.getAmount().multiply(rate);
        return new Money(targetAmount, to);
    }
}